import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layout/index.vue'
import { shouldShowModule } from '@/config/production-modules'

const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/flink-cluster',
    children: [
      // 1. Flink集群管理
      ...(shouldShowModule('flink-cluster') ? [{
        path: 'flink-cluster',
        name: 'FlinkCluster',
        component: () => import('@/views/FlinkCluster/index.vue'),
        meta: { 
          title: 'Flink集群管理', 
          icon: 'DataBoard',
          color: '#ff6b6b' // 红色
        }
      }] : []),
      // 2. 作业管理
      ...(shouldShowModule('jobs') ? [{
        path: 'jobs',
        name: 'Jobs',
        component: () => import('@/views/Jobs/index.vue'),
        meta: { 
          title: '作业管理', 
          icon: 'Folder',
          color: '#67c23a' // 绿色
        }
      }] : []),
      // 3. 日志统计
      ...(shouldShowModule('logs') ? [{
        path: 'logs',
        name: 'Logs',
        component: () => import('@/views/Logs/index.vue'),
        meta: { 
          title: '日志统计', 
          icon: 'Document',
          color: '#9c27b0' // 紫色
        }
      }] : []),
      // 4. 数据工具
      ...(shouldShowModule('tools') ? [{
        path: 'tools',
        name: 'Tools',
        component: () => import('@/views/Tools/index.vue'),
        meta: { 
          title: '数据工具', 
          icon: 'Tools',
          color: '#ff9800' // 橙黄色
        }
      }] : []),
      // 5. Kafka监控管理
      ...(shouldShowModule('kafka-topic-monitor') ? [{
        path: 'kafka-topic-monitor',
        name: 'KafkaTopicMonitor',
        component: () => import('@/views/KafkaMonitor/index.vue'),
        meta: { 
          title: 'Kafka监控管理', 
          icon: 'Operation',
          color: '#409eff' // 蓝色
        }
      }] : []),
      // 6. StarRocks表管理
      ...(shouldShowModule('starrocks-tables') ? [{
        path: 'starrocks-tables',
        name: 'StarRocksTables',
        component: () => import('@/views/Tools/StarRocksTables/index.vue'),
        meta: { 
          title: 'StarRocks表管理', 
          icon: 'Coin',
          color: '#9c27b0' // 紫色
        }
      }] : []),
      {
        path: 'tools/starrocks-tables/:id/stats',
        name: 'StarRocksTableStats',
        component: () => import('@/views/Tools/StarRocksTables/Stats.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，作为详情页面
      },
      // 7. 告警管理
      ...(shouldShowModule('alerts') ? [{
        path: 'alerts',
        name: 'Alerts',
        component: () => import('@/views/Alerts/index.vue'),
        meta: { 
          title: '告警管理', 
          icon: 'Bell',
          color: '#f56c6c' // 红色
        }
      }] : []),
      // 8. Savepoint记录
      ...(shouldShowModule('savepoints') ? [{
        path: 'savepoints',
        name: 'Savepoints',
        component: () => import('@/views/Savepoints/index.vue'),
        meta: { 
          title: 'Savepoint记录', 
          icon: 'Files',
          color: '#e6a23c' // 橙色
        }
      }] : []),
      // 9. JAR管理
      ...(shouldShowModule('jars') ? [{
        path: 'jars',
        name: 'Jars',
        component: () => import('@/views/Jars/index.vue'),
        meta: { 
          title: 'JAR管理', 
          icon: 'List',
          color: '#409eff' // 蓝色
        }
      }] : []),
      // 10. 三方配置
      ...(shouldShowModule('third-party-config') ? [{
        path: 'third-party-config',
        name: 'ThirdPartyConfig',
        component: () => import('@/views/Settings/index.vue'),
        meta: { 
          title: '三方配置', 
          icon: 'Link',
          color: '#00bcd4' // 青色
        }
      }] : []),
      // 11. StarRocks监控管理
      ...(shouldShowModule('starrocks-cluster-monitor') ? [{
        path: 'starrocks-cluster-monitor',
        name: 'StarRocksMonitor',
        component: () => import('@/views/StarRocksMonitor/index.vue'),
        meta: { 
          title: 'StarRocks监控管理',
          icon: 'DataLine',
          color: '#667eea' // 紫蓝色
        }
      }] : []),
      // 12. 报表管理（通过配置文件控制）
      ...(shouldShowModule('reports') ? [{
        path: 'reports',
        name: 'Reports',
        component: () => import('@/views/Reports/index.vue'),
        meta: { 
          title: '报表管理', 
          icon: 'Document',
          color: '#34d399', // 绿色
          devOnly: !shouldShowModule('reports') // 标记为仅开发环境
        }
      }] : []),
      // 13. 前端开发模版（仅开发环境）
      ...(shouldShowModule('dev-template') ? [{
        path: 'dev-template',
        name: 'DevTemplate',
        component: () => import('@/views/DevTemplate/index.vue'),
        meta: { 
          title: '前端开发模版', 
          icon: 'Document',
          color: '#9c27b0', // 紫色
          devOnly: true // 标记为仅开发环境
        }
      }] : []),
      // 14. Redis监控系统
      ...(shouldShowModule('redis-task-monitor') ? [{
        path: 'redis-task-monitor',
        name: 'RedisTaskMonitor',
        component: () => import('@/views/RedisTaskMonitor/index.vue'),
        meta: { 
          title: 'Redis任务监控管理', 
          icon: 'Monitor',
          color: '#dc2626' // 红色
        }
      }] : []),
      // Redis监控系统 - 子页面（隐藏）
      {
        path: 'redis-task-monitor/task-config',
        name: 'RedisTaskConfig',
        component: () => import('@/views/RedisTaskMonitor/TaskConfigPage.vue'),
        meta: { hidden: true }
      },
      {
        path: 'redis-task-monitor/queue-config',
        name: 'RedisQueueConfig',
        component: () => import('@/views/RedisTaskMonitor/QueueConfigPage.vue'),
        meta: { hidden: true }
      },
      // Flink监控配置（从Jobs页面访问）
      {
        path: 'flink-monitor-config',
        name: 'FlinkMonitorConfig',
        component: () => import('@/views/FlinkMonitorConfig/index.vue'),
        meta: { 
          title: 'Flink监控配置',
          icon: 'Setting',
          hidden: true
        }
      },
      // 重启历史（从Jobs页面访问）
      {
        path: 'restart-history',
        name: 'RestartHistory',
        component: () => import('@/views/RestartHistory/index.vue'),
        meta: { 
          title: '重启历史',
          icon: 'Refresh',
          hidden: true
        }
      },
      // 工具页面的子路由（不显示在主菜单）
      {
        path: 'tools/api-listener',
        name: 'ApiListener',
        component: () => import('@/views/Tools/ApiListener/index.vue'),
        meta: { icon: 'Link' }
      },
      {
        path: 'tools/kafka-monitor',
        name: 'KafkaMonitor',
        component: () => import('@/views/Tools/KafkaMonitor/index.vue'),
        meta: { icon: 'Monitor' }
      },
      {
        path: 'tools/kafka-forward',
        name: 'KafkaForward',
        component: () => import('@/views/Tools/KafkaForward/index.vue'),
        meta: { icon: 'Connection' }
      },
      {
        path: 'tools/timestamp-converter',
        name: 'TimestampConverter',
        component: () => import('@/views/Tools/TimestampConverter/index.vue'),
        meta: { icon: 'Clock' }
      },
      {
        path: 'tools/starrocks',
        name: 'StarRocks',
        component: () => import('@/views/Tools/StarRocks/index.vue'),
        meta: { icon: 'DataLine' }
      },
      {
        path: 'tools/callback',
        name: 'Callback',
        component: () => import('@/views/Tools/Callback/index.vue'),
        meta: { icon: 'Message' }
      },
      {
        path: 'tools/json-formatter',
        name: 'JsonFormatter',
        component: () => import('@/views/Tools/JsonFormatter/index.vue'),
        meta: { icon: 'Document' }
      },
      // 日志统计子页面（不显示在主菜单）
      {
        path: 'logs/api',
        name: 'SpringApiLogs',
        component: () => import('@/views/Logs/SpringApi.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/api/list',
        name: 'SpringApiLogsList',
        component: () => import('@/views/Logs/SpringApiList.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/minio',
        name: 'MinioAuditLogs',
        component: () => import('@/views/Logs/MinioAudit.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/minio/list',
        name: 'MinioAuditLogsList',
        component: () => import('@/views/Logs/MinioAuditList.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/flink-job',
        name: 'FlinkJobLogs',
        component: () => import('@/views/Logs/FlinkJobLogs.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/flink-job/list',
        name: 'FlinkJobLogsList',
        component: () => import('@/views/Logs/FlinkJobLogsList.vue'),
        meta: { hidden: true }  // 隐藏在菜单中，通过主页卡片访问
      },
      {
        path: 'logs/starrocks-error',
        name: 'StarrocksErrorLogs',
        component: () => import('@/views/Logs/StarrocksErrorLogs.vue'),
        meta: { hidden: true }
      },
      {
        path: 'logs/starrocks-error/list',
        name: 'StarrocksErrorLogsList',
        component: () => import('@/views/Logs/StarrocksErrorLogsList.vue'),
        meta: { hidden: true }
      },
      {
        path: 'logs/starrocks-query',
        name: 'StarrocksQueryLogs',
        component: () => import('@/views/Logs/StarrocksQueryLogs.vue'),
        meta: { hidden: true }
      },
      {
        path: 'logs/starrocks-query/list',
        name: 'StarrocksQueryLogsList',
        component: () => import('@/views/Logs/StarrocksQueryLogsList.vue'),
        meta: { hidden: true }
      }
    ]
  },
  // 报表分享页面（独立页面，不使用Layout）
  {
    path: '/reports/share/:runId',
    name: 'ReportShare',
    component: () => import('@/views/Reports/Share.vue'),
    meta: { 
      title: '报表分享',
      layout: false // 标记为不使用Layout
    }
  },
  // 报表预览页面（独立页面，不使用Layout）
  {
    path: '/reports/preview/:runId/:fileId',
    name: 'ReportPreview',
    component: () => import('@/views/Reports/Preview.vue'),
    meta: { 
      title: '报表预览',
      layout: false // 标记为不使用Layout
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
